import { Field, InputType, Int, ObjectType, PartialType } from "@nestjs/graphql";
import { GraphQLBigInt } from "graphql-scalars";
import { BaseCreateSchema, PageInput, PaginatedResponse } from "src/common/mongodb/commonSchema";
import { User } from "../entities/user.entity";
import { MongoQueryScalar } from "src/common/scalars/mongo.query.scalar";

/** 创建用户输入DTO */
@InputType()
export class CreateUserInput extends BaseCreateSchema {
  @Field(() => String) name: string;

  @Field(() => String) email: string;

  @Field(() => String) password: string;

  @Field(() => String) address: string;

  @Field(() => String) username: string;

  @Field(() => Int) gender: number;

  @Field(() => GraphQLBigInt) role: number;
}

/** 更新用户输入DTO */
@InputType()
export class UpdateUserInput extends PartialType(CreateUserInput) {
  @Field(() => GraphQLBigInt)
  id: number;
}

/** 登录用户输入DTO */
@InputType()
export class LoginUserInput {
  @Field(() => String)
  email: string;

  @Field()
  password: string;
}

/** 更新密码输入DTO */
@InputType()
export class UpdatePasswordInput {
  @Field(() => Int)
  id: number;

  @Field(() => String)
  password: string;
}

/** 搜索用户输入DTO */
@InputType()
export class SearchUserInput {
  @Field(() => GraphQLBigInt, { nullable: true }) _id: number;

  @Field(() => MongoQueryScalar, { nullable: true }) name: string;

  @Field(() => MongoQueryScalar, { nullable: true }) email: string;

  @Field(() => MongoQueryScalar, { nullable: true }) address: string;

  @Field(() => MongoQueryScalar, { nullable: true }) username: string;

  @Field(() => MongoQueryScalar, { nullable: true }) gender: string;
}

/** 分页查询用户输入DTO */
@InputType()
export class PageUserInput extends PageInput<SearchUserInput>(SearchUserInput) {
}


@ObjectType()
export class PageUserResponse extends
  PaginatedResponse<User>(User) {
}

@ObjectType()
export class LoginUserResponse {
  @Field(() => User)
  user: User;

  @Field()
  token: string;

  @Field()
  expires: number;
}




